﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Zero.Data;

namespace Zero.Service
{
  
    public interface IService<T> where T : BaseEntity
    {
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        T Get(object id);

        /// <summary>
        /// 获取所有实体
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAll();


        /// <summary>
        /// 获取满足条件的实体集合
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> GetMany(Expression<Func<T, bool>> where);

        /// <summary>
        /// 根据键值获取指定实体
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        T Find(params object[] keys);

        /// <summary>
        /// 根据表达式条件获取实体
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        T Find(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 分页获取指定实体集合
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        IQueryable<T> GetByPage(Expression<Func<T, bool>> filter, out int total, int page, int size);


        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity"></param>
        void Add(T entity);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity"></param>
        void Update(T entity);

        /// <summary>
        /// 物理删除实体
        /// </summary>
        /// <param name="entity"></param>
        void Remove(T entity);

        /// <summary>
        /// 根据物理删除实体
        /// </summary>
        /// <param name="id">主键</param>
        void Remove(object id);

        /// <summary>
        /// 逻辑删除实体
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);

        /// <summary>
        /// 根据主键逻辑删除实体
        /// </summary>
        /// <param name="id"></param>
        void Delete(object id);

        /// <summary>
        /// 逻辑删除满足条件的实体集合
        /// </summary>
        /// <param name="where"></param>
        void Delete(Expression<Func<T, bool>> where);
    }
}
